﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.IO;

namespace Secure.FTPDeliveryExtension
{
    internal static class Globals
    {
        // Methods
        public static XmlTextReader SafeCreateXmlTextReader(Stream xmlStream)
        {
            XmlTextReader reader = new XmlTextReader(xmlStream);
            reader.ProhibitDtd = true;
            return reader;
        }

        public static XmlTextReader SafeCreateXmlTextReader(string xmlContent)
        {
            StringReader input = new StringReader(xmlContent);
            XmlTextReader reader2 = new XmlTextReader(input);
            reader2.ProhibitDtd = true;
            return reader2;
        }

        public static void SafeOpenXmlDocumentFile(XmlDocument doc, string pathToXmlFile)
        {
            FileStream input = new FileStream(pathToXmlFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
            try
            {
                XmlTextReader reader = new XmlTextReader(input);
                reader.ProhibitDtd = true;
                doc.Load(reader);
            }
            finally
            {
                input.Close();
            }
        }

        public static void SafeOpenXmlDocumentString(XmlDocument doc, string xmlContent)
        {
            StringReader input = new StringReader(xmlContent);
            XmlTextReader reader = new XmlTextReader(input);
            reader.ProhibitDtd = true;
            reader.MoveToContent();
            doc.Load(reader);
        }
    }
}
